import 'package:flutter/material.dart';
import '../../utils/resability.dart'; // 导入控制器
import 'package:carousel_slider/carousel_slider.dart';

class BookshelfPage extends StatelessWidget {
  BookshelfPage({super.key});

  final List<String> images = [
    'assets/images/banner/1.png',
    'assets/images/banner/2.png',
    'assets/images/banner/3.png',
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: bg_color_light,
      appBar: AppBar(
        backgroundColor: bg_color_light,
        title: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            IconButton(
              onPressed: () {},
              icon: Icon(Icons.menu, color: Colors.white.withAlpha(0)),
            ),
            Text('书架', style: TextStyle(color: Colors.white, fontSize: 20)),
            IconButton(
              onPressed: () {},
              icon: Icon(Icons.menu, color: Colors.white),
            ),
          ],
        ),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            //轮播图
            CarouselSlider(
              options: CarouselOptions(
                height: 200,
                autoPlay: true,
                enlargeCenterPage: true,
                aspectRatio: 16 / 9,
                autoPlayCurve: Curves.decelerate,
                enableInfiniteScroll: true,
                viewportFraction: 0.88,
                autoPlayAnimationDuration: Duration(milliseconds: 800),
              ),
              items:
                  images.map((imageUrl) {
                    return Builder(
                      builder: (BuildContext context) {
                        return Container(
                          width: MediaQuery.of(context).size.width,
                          margin: EdgeInsets.symmetric(horizontal: 5.0),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(8.0),
                            image: DecorationImage(
                              image: AssetImage(imageUrl),
                              fit: BoxFit.cover,
                            ),
                          ),
                        );
                      },
                    );
                  }).toList(),
            ),
            //正在阅读
            Container(
              width: double.infinity,
              padding: EdgeInsets.fromLTRB(30, 15, 30, 0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Text(
                    '正在阅读',
                    style: TextStyle(color: Colors.white, fontSize: 20),
                  ),
                  // 填补中间空缺
                  Spacer(),
                  TextButton(
                    onPressed: () {},
                    style: TextButton.styleFrom(padding: EdgeInsets.zero),
                    child: Text(
                      '查看更多 >',
                      style: TextStyle(color: text_color_light, fontSize: 14),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(height: 10),
            Container(
              padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(10),
                        child: Image.asset(
                          'assets/images/fengmian/1.png',
                          width: 100,
                        ),
                      ),
                      SizedBox(height: 10),
                      SizedBox(
                        width: 100,
                        child: Text(
                          '活着',
                          style: TextStyle(color: Colors.white, fontSize: 15),
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                      SizedBox(
                        width: 100,
                        child: Text(
                          '余华',
                          style: TextStyle(color: text_color, fontSize: 13),
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                    ],
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(10),
                        child: Image.asset(
                          'assets/images/fengmian/5.png',
                          width: 100,
                        ),
                      ),
                      SizedBox(height: 10),
                      SizedBox(
                        width: 100,
                        child: Text(
                          '哈利波特与缅北',
                          style: TextStyle(color: Colors.white, fontSize: 15),
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                      SizedBox(
                        width: 100,
                        child: Text(
                          '麻瓜',
                          style: TextStyle(color: text_color, fontSize: 13),
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                    ],
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(10),
                        child: Image.asset(
                          'assets/images/fengmian/3.png',
                          width: 100,
                        ),
                      ),
                      SizedBox(height: 10),
                      SizedBox(
                        width: 100,
                        child: Text(
                          '三体',
                          style: TextStyle(color: Colors.white, fontSize: 15),
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                      SizedBox(
                        width: 100,
                        child: Text(
                          '刘慈欣',
                          style: TextStyle(color: text_color, fontSize: 13),
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
            Container(
              width: double.infinity,
              margin: EdgeInsets.fromLTRB(30, 0, 30, 10),
              height: 1,
              color: bg_color_light,
            ),
          ],
        ),
      ),
    );
  }
}
